﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;
using LotteryVote.Utility;

namespace LotteryVote
{
    public partial class UpperLimitManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCompany();
                BindGamePlayWay();
            }
        }

        void BindCompany()
        {
            CompanyFacade companyFacade = new CompanyFacade();
            ddl_companys.DataSource = companyFacade.GetAllCompany();
            ddl_companys.DataTextField = LotteryCompany.NAME;
            ddl_companys.DataValueField = LotteryCompany.COMPANYID;
            ddl_companys.DataBind();
        }

        void BindGamePlayWay()
        {
            GamePlayWayFacade gpwFacade = new GamePlayWayFacade();
            ddl_gameplayway.DataSource = gpwFacade.GetAllGamePlayWay().Select(it => new { GamePlayWayId = it.Id, Name = it.GameType.GameName + "=>" + it.PlayWay.WayName });
            ddl_gameplayway.DataTextField = "Name";
            ddl_gameplayway.DataValueField = "GamePlayWayId";
            ddl_gameplayway.DataBind();
        }

        protected void btn_initUpperLimit_Click(object sender, EventArgs e)
        {
            DefaultUpperLimitFacade blUpperLimit = new DefaultUpperLimitFacade();
            blUpperLimit.InitDefaultUpperLimit(decimal.Parse(txt_limitAmount.Text));
        }

        protected void btn_Add2DAutoDrop_Click(object sender, EventArgs e)
        {
            DropWaterFacade blDropWater = new DropWaterFacade();
            blDropWater.Add2DAutoDropWater(float.Parse(txt_dropValue.Text), decimal.Parse(txt_dropAmount.Text));
        }

        protected void btn_addManualDrop_Click(object sender, EventArgs e)
        {
            DropWaterFacade blDropWater = new DropWaterFacade();
            blDropWater.AddDropWater(txt_num.Text, int.Parse(ddl_gameplayway.SelectedValue),
                double.Parse(txt_manualDropValue.Text), decimal.Parse(txt_manualAmount.Text), int.Parse(ddl_companys.SelectedValue));
        }
    }
}